home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!usenet
- From: nabbasi@qualcomm.com (Nasser Abbasi)
- Newsgroups: comp.lang.c++
- Subject: Re: How to handle error in constructor
- Date: 31 Jan 1996 22:54:29 GMT
- Organization: QUALCOMM
- Distribution: world
- Message-ID: <4eorv5$416@qualcomm.com>
- References: <DLyyIM.5EG@teslab.lab.oz.au> <4eo6n6$rbp@cnn.exu.ericsson.se>
- NNTP-Posting-Host: nabbasi.qualcomm.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4eo6n6$rbp@cnn.exu.ericsson.se>, ebumow@ebu.ericsson.com
- says...
-
- >
- >That's because exception handling is the way to handle errors using
- >C++ nowadays.
- >
-
- Exception handling is a clean and natural way to handle errors in the
- program. No one will argue with that. However, using exception handling
- correctly in not always that easy or simple . that is why things like
- auto pointers are being considered to add to C++ ansi standard. But using
- exception handling correclty is really the best solution most of the
- times.
-
- As to original question, as some one else suggested, you can instead have
- an init() function that you call to do the initializations that you need
- to do .
-
- You need to make sure to protect the object against being initialized
- more than once if the object is gloabl !
-
- In a single threaded application, this is easy to
- do via a an internal static flag inside the object private area
- initialized correclty, in a multi-threaded applications, with a global
- object, you need offcourse to make sure the checking on the internal flag
- is in a critical section befor you do the test-and-set operation.
-
- It is possible that intializing an object more than once can lead to a
- disaster !
-
- There are many things to do something, and choosing the best and most
- natural way of coding something is what makes programming both an art
- and a sicence, and offcourse fun!
-
- Nasser
-
-